import { get, post, put } from "../http";
import type { CursorPage } from "../types";
import type { ArticleCreateFn, ArticleGetFn, ArticlesGetFn, ArticleUpdateFn, ArticleView } from "./article.types";

export const articleCreate: ArticleCreateFn = async (input) => post<string>({ url: "/apis/articles", json: input });

export const articleUpdate: ArticleUpdateFn = async (uid, input) =>
  put<string>({ url: `/apis/articles/${uid}`, json: input });

export const articleGet: ArticleGetFn = async (uid) => get<ArticleView>({ url: `/apis/articles/${uid}` });

export const articlesGet: ArticlesGetFn = async (input) =>
  get<CursorPage<ArticleView, string>>({ url: "/apis/articles", qs: input });
